package com.example.purplestarcb.shoujizhushou;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.view.View;
import android.widget.Toast;

public class Setup2Activity extends BaseSetupActivity {

    private SettingItemView sivSim;
    //读取sim卡
    private TelephonyManager tm;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setup2);
        sivSim= (SettingItemView) findViewById(R.id.siv_sim);
        tm= (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
        String sim= sp.getString("sim",null);
        if (TextUtils.isEmpty(sim)){
            sivSim.setChecked(false);
        }else {
            sivSim.setChecked(true);
        }
        sivSim.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SharedPreferences.Editor editor=sp.edit();
                if(sivSim.isChecked()){
                    sivSim.setChecked(false);
                    editor.putString("sim","");
                }else{
                    //保存sim卡序列号
                    sivSim.setChecked(true);
                    String sim = tm.getSimSerialNumber();
                    editor.putString("sim",sim);

                }
                editor.apply();

            }
        });
    }

    @Override
    public void showNext() {
        String sim=sp.getString("sim",null);
        if (TextUtils.isEmpty(sim)){
            Toast.makeText(this, "请返回绑定SIM卡", 1).show();
            System.out.println("请返回绑定SIM卡");
            return;
        }

        Intent intent = new Intent(this,Setup3Activity.class);
        startActivity(intent);
        finish();
        //要求在finish()或者startActivity(intent);后面执行；
        overridePendingTransition(R.anim.tran_in, R.anim.tran_out);

    }

    @Override
    public void showPre() {
        Intent intent = new Intent(this,Setup1Activity.class);
        startActivity(intent);
        finish();
        //要求在finish()或者startActivity(intent);后面执行；
        overridePendingTransition(R.anim.tran_pre_in, R.anim.tran_pre_out);

    }
}
